package main.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import main.controller.Login;
import main.model.User;
import main.view.Main;
public class LoginDB {
    public String login(String username,String password) throws SQLException{

        String sql="select * from user where username=? and password=?";
        Connection con = new Main().getConnection();
        PreparedStatement ps=con.prepareStatement(sql);
        ps.setString(1,username);
        ps.setString(2, password);
        ResultSet rs=ps.executeQuery();
        if(rs.next()){
            System.out.println("isOK");
            Object edit = null;
            User temp = new User(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),edit);
            Login.momentUser = temp;
            return "isOK";
        }else{
            System.out.println("error");
            return "error";
        }
    }
}
